<template>
  <div>
    <el-cascader
      v-model="value"
      :options="normalizedOptions"
      :placeholder="'请选择'"
      style="width:100%;"
      :props="{multiple:true}"
      @change="handleChange">
    </el-cascader>
  </div>
</template>

<script lang='ts'>
    import { Component, Prop, Vue } from 'vue-property-decorator';
    import { getLvList } from '@/base/api/LvApi';

    @Component
    export default class UserSelector extends Vue {
        @Prop({ type: String })
        readonly targetAccounts! : string;

        value: Array<any>=[];
        options: Array<any>=[];
        normalizedOptions:Array<any>=[];
        async created () {
            await this.load(1, 100);
            this.normalizedOptions = this.options.map((name, index) => ({
                value: index + 1,
                label: name
            }));
            if (this.targetAccounts) {
                this.value = JSON.parse(this.targetAccounts);
            }
        }
        handleChange(value) {
            // console.log(value);
            this.$emit('change', value, 0)
        }
        load(pageIndex: number, pageSize: number) {
            return getLvList({
                pageIndex,
                pageSize,
                sortDirection: 'ASC'
            }).then((res) => {
               res.data.items.forEach((item) => {
                   this.options.push(item.name)
               })
            }).finally(() => {
            });
        }
    }
</script>

<style scoped>
  /deep/ .popper .el-cascader-panel .el-checkbox{
    padding: 10px 50px;
  }
</style>
